﻿Imports System.Data.SqlClient

Public Class clsMATERIALES
    Private mintIDMaterial As Integer
    Public Property IDMATERIAL() As Integer
        Get
            Return mintIDMaterial
        End Get
        Set(ByVal value As Integer)
            mintIDMaterial = value
        End Set
    End Property
    Public Sub New()
        mintIDMaterial = 0
    End Sub
    Public Sub GUARDA_ARTICULO_GENERALES(ByVal CODIGO As String, ByVal NOMBRE As String, ByVal DESCRIPCION As String, ByVal CLASIF1 As String, ByVal CLASIF2 As String, ByVal CLASIF3 As String, ByVal UNIDAD As String, ByVal CODIGO_SAE As String, ByVal MONEDA As String, ByVal CODIGO_ALTERNO As String, ByVal DIAS As Integer, ByVal TIPO As String, ByVal COLOR As String, ByVal COMPOSICION As String)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_MATERIALES_INSERTAR", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters.Add(New SqlParameter("@DESCRIPCION", SqlDbType.VarChar, 1000))
        Command.Parameters("@DESCRIPCION").Value = DESCRIPCION
        Command.Parameters.Add(New SqlParameter("@CLASIF1", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF1").Value = CLASIF1
        Command.Parameters.Add(New SqlParameter("@CLASIF2", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF2").Value = CLASIF2
        Command.Parameters.Add(New SqlParameter("@CLASIF3", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF3").Value = CLASIF3
        Command.Parameters.Add(New SqlParameter("@UNIDAD", SqlDbType.VarChar, 100))
        Command.Parameters("@UNIDAD").Value = UNIDAD
        Command.Parameters.Add(New SqlParameter("@CODIGO_SAE", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO_SAE").Value = CODIGO_SAE
        Command.Parameters.Add(New SqlParameter("@MONEDA", SqlDbType.VarChar, 30))
        Command.Parameters("@MONEDA").Value = MONEDA
        Command.Parameters.Add(New SqlParameter("@CODIGO_ALTERNO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO_ALTERNO").Value = CODIGO_ALTERNO
        Command.Parameters.Add(New SqlParameter("@DIAS", SqlDbType.Int))
        Command.Parameters("@DIAS").Value = DIAS
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.VarChar, 30))
        Command.Parameters("@TIPO").Value = TIPO
        Command.Parameters.Add(New SqlParameter("@COLOR", SqlDbType.VarChar, 30))
        Command.Parameters("@COLOR").Value = COLOR
        Command.Parameters.Add(New SqlParameter("@COMPOSICION", SqlDbType.VarChar, 30))
        Command.Parameters("@COMPOSICION").Value = COMPOSICION

        Dim Lector As SqlDataReader
        Try
            cnConn.Open()

            Lector = Command.ExecuteReader
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Sub
    Public Sub ACTUALIZA_IMPUESTOS_RETENCIONES(ByVal CODIGO As String, ByVal Impuesto1 As Double, ByVal Impuesto2 As Double, ByVal Impuesto3 As Double, ByVal Retencion1 As Double, ByVal Retencion2 As Double, ByVal Retencion3 As Double)
        Dim sql As String = "UPDATE MATERIALES SET " & _
                            "IMPUESTO1=@IMPUESTO1," & _
                            "IMPUESTO2=@IMPUESTO2," & _
                            "IMPUESTO3=@IMPUESTO3," & _
                            "RETENCION1=@RETENCION1," & _
                            "RETENCION2=@RETENCION2," & _
                            "RETENCION3=@RETENCION3 " & _
                            "WHERE CODIGO=@CODIGO"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CODIGO", CODIGO)
        Command.Parameters.AddWithValue("IMPUESTO1", Impuesto1)
        Command.Parameters.AddWithValue("IMPUESTO2", Impuesto2)
        Command.Parameters.AddWithValue("IMPUESTO3", Impuesto3)
        Command.Parameters.AddWithValue("RETENCION1", Retencion1)
        Command.Parameters.AddWithValue("RETENCION2", Retencion2)
        Command.Parameters.AddWithValue("RETENCION3", Retencion3)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try


    End Sub
    Public Function INSERTA_MATERIAL(ByVal CODIGO As String, ByVal NOMBRE As String, ByVal DESCRIPCION As String, ByVal FOTO As Byte, ByVal ESTATUS As Integer, ByVal UNIDAD1 As String, ByVal CLASIF1 As String, ByVal CLASIF2 As String, ByVal CLASIF3 As String, ByVal MONEDA As String, ByVal CODIGO_SAE As String, ByVal DIAS As Integer, ByVal TIPO As String, ByVal COLOR As String, ByVal COMPOSICION As String, ByVal TIPO_PRO As Integer, ByVal PRECIO As Double, ByVal UNIDAD2 As String, ByVal EXISTENCIA As Double, ByVal TRANSITO As Double, ByVal ESTADO As Integer, ByVal ADMINISTRADOR As String, ByVal VOLUMEN As Double, ByVal BRUTO As Double, ByVal NETO As Double, ByVal ESPESOR As Double, ByVal LARGO As Double, ByVal ALTO As Double, ByVal ANCHO As Double, ByVal DESC2 As String, ByVal UBICACION As String, ByVal TIPOS As Integer, ByVal ORIGEN As Integer, ByVal ALMACEN As String)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_MATERIALES_CAT", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters.Add(New SqlParameter("@DESCRIPCION", SqlDbType.VarChar, 1000))
        Command.Parameters("@DESCRIPCION").Value = DESCRIPCION
        'Command.Parameters.Add(New SqlParameter("@FOTO", SqlDbType.Image))
        'Command.Parameters("@FOTO").Value = Nothing
        Command.Parameters.Add(New SqlParameter("@ESTATUS", SqlDbType.Int))
        Command.Parameters("@ESTATUS").Value = ESTATUS
        Command.Parameters.Add(New SqlParameter("@UNIDAD", SqlDbType.VarChar, 100))
        Command.Parameters("@UNIDAD").Value = UNIDAD1
        Command.Parameters.Add(New SqlParameter("@CLASIF1", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF1").Value = CLASIF1
        Command.Parameters.Add(New SqlParameter("@CLASIF2", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF2").Value = CLASIF2
        Command.Parameters.Add(New SqlParameter("@CLASIF3", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF3").Value = CLASIF3
        Command.Parameters.Add(New SqlParameter("@MONEDA", SqlDbType.VarChar, 100))
        Command.Parameters("@MONEDA").Value = MONEDA
        Command.Parameters.Add(New SqlParameter("@CODIGO_SAE", SqlDbType.VarChar, 50))
        Command.Parameters("@CODIGO_SAE").Value = CODIGO_SAE
        Command.Parameters.Add(New SqlParameter("@DIAS_ANTICIPACION", SqlDbType.Int))
        Command.Parameters("@DIAS_ANTICIPACION").Value = DIAS
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.VarChar, 100))
        Command.Parameters("@TIPO").Value = TIPO
        Command.Parameters.Add(New SqlParameter("@COLOR", SqlDbType.VarChar, 100))
        Command.Parameters("@COLOR").Value = COLOR
        Command.Parameters.Add(New SqlParameter("@COMPOSICION", SqlDbType.VarChar, 100))
        Command.Parameters("@COMPOSICION").Value = COMPOSICION
        Command.Parameters.Add(New SqlParameter("@TIPO_PRO", SqlDbType.Int))
        Command.Parameters("@TIPO_PRO").Value = TIPO_PRO
        Command.Parameters.Add(New SqlParameter("@PRECIO", SqlDbType.Decimal))
        Command.Parameters("@PRECIO").Value = PRECIO
        Command.Parameters.Add(New SqlParameter("@UNIDAD_COMPRA", SqlDbType.VarChar, 30))
        Command.Parameters("@UNIDAD_COMPRA").Value = UNIDAD2
        Command.Parameters.Add(New SqlParameter("@EXISTENCIA", SqlDbType.Decimal))
        Command.Parameters("@EXISTENCIA").Value = EXISTENCIA
        Command.Parameters.Add(New SqlParameter("@TRANSITO", SqlDbType.Decimal))
        Command.Parameters("@TRANSITO").Value = TRANSITO
        Command.Parameters.Add(New SqlParameter("@ESTADO", SqlDbType.Int))
        Command.Parameters("@ESTADO").Value = ESTADO
        Command.Parameters.Add(New SqlParameter("@NOMBRE_ADMON", SqlDbType.VarChar, 200))
        Command.Parameters("@NOMBRE_ADMON").Value = ADMINISTRADOR
        Command.Parameters.Add(New SqlParameter("@VOLUMEN", SqlDbType.Decimal))
        Command.Parameters("@VOLUMEN").Value = VOLUMEN
        Command.Parameters.Add(New SqlParameter("@PESO_BRUTO", SqlDbType.Decimal))
        Command.Parameters("@PESO_BRUTO").Value = BRUTO
        Command.Parameters.Add(New SqlParameter("@PESO_NETO", SqlDbType.Decimal))
        Command.Parameters("@PESO_NETO").Value = NETO
        Command.Parameters.Add(New SqlParameter("@ESPESOR", SqlDbType.Decimal))
        Command.Parameters("@ESPESOR").Value = ESPESOR
        Command.Parameters.Add(New SqlParameter("@LARGO", SqlDbType.Decimal))
        Command.Parameters("@LARGO").Value = LARGO
        Command.Parameters.Add(New SqlParameter("@ALTO", SqlDbType.Decimal))
        Command.Parameters("@ALTO").Value = ALTO
        Command.Parameters.Add(New SqlParameter("@ANCHO", SqlDbType.Decimal))
        Command.Parameters("@ANCHO").Value = ANCHO
        Command.Parameters.Add(New SqlParameter("@NOMBRE_USUARIO", SqlDbType.VarChar, 50))
        Command.Parameters("@NOMBRE_USUARIO").Value = UsuarioActivo
        Command.Parameters.Add(New SqlParameter("@NUM1", SqlDbType.Int))
        Command.Parameters("@NUM1").Value = CLASIFICACIONES_MATERIALES.Clasificacion_1
        Command.Parameters.Add(New SqlParameter("@NUM2", SqlDbType.Int))
        Command.Parameters("@NUM2").Value = CLASIFICACIONES_MATERIALES.Clasificacion_2
        Command.Parameters.Add(New SqlParameter("@NUM3", SqlDbType.Int))
        Command.Parameters("@NUM3").Value = CLASIFICACIONES_MATERIALES.Clasificacion_3
        Command.Parameters.Add(New SqlParameter("@DESCRIPCION2", SqlDbType.VarChar, 1000))
        Command.Parameters("@DESCRIPCION2").Value = DESC2
        Command.Parameters.Add(New SqlParameter("@UBICACION", SqlDbType.VarChar, 200))
        Command.Parameters("@UBICACION").Value = UBICACION
        Command.Parameters.Add(New SqlParameter("@TIPOS", SqlDbType.Int))
        Command.Parameters("@TIPOS").Value = TIPOS
        Command.Parameters.Add(New SqlParameter("@ORIGEN", SqlDbType.Int))
        Command.Parameters("@ORIGEN").Value = ORIGEN
        Command.Parameters.Add(New SqlParameter("@ALMACEN", SqlDbType.VarChar, 200))
        Command.Parameters("@ALMACEN").Value = ALMACEN

        Dim Lector As SqlDataReader
        Try
            cnConn.Open()

            Lector = Command.ExecuteReader
            If Lector.Read() Then
                INSERTA_MATERIAL = Lector("RESULTADO")
                mintIDMaterial = Lector("IDPRODUCTO")
            End If
        Catch ex As Exception
            INSERTA_MATERIAL = -1
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Function
    Public Sub INSERTA_PROVEEDOR(ByVal IDPRODUCTO As Integer, ByVal PROVEEDOR As String, ByVal CODIGO As String, ByVal NOMBRE As String, ByVal IDUNIDAD As Integer, ByVal DIAS_EMNAR As Integer, ByVal DIAS_GAR As Integer, ByVal DIAS_ENTREGA As Integer, ByVal PRECIO As Double, ByVal MINIMO As Double)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_MATERIALES_PROVEEDORES", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@IDPRODUCTO", SqlDbType.Int))
        Command.Parameters("@IDPRODUCTO").Value = IDPRODUCTO
        Command.Parameters.Add(New SqlParameter("@PROVEEDOR", SqlDbType.VarChar, 200))
        Command.Parameters("@PROVEEDOR").Value = PROVEEDOR
        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters.Add(New SqlParameter("@IDUNIDAD", SqlDbType.Int))
        Command.Parameters("@IDUNIDAD").Value = IDUNIDAD
        Command.Parameters.Add(New SqlParameter("@GARANTIA", SqlDbType.Int))
        Command.Parameters("@GARANTIA").Value = DIAS_GAR
        Command.Parameters.Add(New SqlParameter("@EMBARQUE", SqlDbType.Int))
        Command.Parameters("@EMBARQUE").Value = DIAS_EMNAR
        Command.Parameters.Add(New SqlParameter("@ENTREGA", SqlDbType.Int))
        Command.Parameters("@ENTREGA").Value = DIAS_ENTREGA
        Command.Parameters.Add(New SqlParameter("@PRECIO", SqlDbType.Decimal))
        Command.Parameters("@PRECIO").Value = PRECIO
        Command.Parameters.Add(New SqlParameter("@MINIMO", SqlDbType.Decimal))
        Command.Parameters("@MINIMO").Value = MINIMO
        Command.Parameters.Add(New SqlParameter("@NOMBRE_USUARIO", SqlDbType.VarChar, 50))
        Command.Parameters("@NOMBRE_USUARIO").Value = UsuarioActivo



        Try
            cnConn.Open()

            Command.ExecuteNonQuery()

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try

    End Sub
   
End Class
